package cn.itlight.basic.service.impl;

import cn.itlight.basic.mapper.BaseMapper;
import cn.itlight.basic.query.BaseQuery;
import cn.itlight.basic.service.IBaseService;
import cn.itlight.basic.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> baseMapper;
    /*
     * @Title: loadAll
     * @Description: TODO
     * @Author: TomLiu
     * @Version: 1.0
     * @Date:  2022/6/21 18:40
     * @Parameters:
     * @Return
     */
    @Override
    public List<T> loadAll() {
        return baseMapper.loadAll();
    }

    /*
     * @Title: loadById
     * @Description: TODO
     * @Author: TomLiu
     * @Version: 1.0
     * @Date:  2022/6/21 18:40
     * @Parameters:
     * @Return
     */
    @Override
    public T loadById(Long id) {
        return baseMapper.loadById(id);
    }

    /*
     * @Title: remove
     * @Description: TODO
     * @Author: TomLiu
     * @Version: 1.0
     * @Date:  2022/6/21 18:40
     * @Parameters:
     * @Return
     */
    @Override
    @Transactional
    public void remove(Long id) {
        baseMapper.remove(id);
    }
    @Override
    @Transactional
    public void save(T t) {
        baseMapper.save(t);
    }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }
    /*
     * @Title: queryData
     * @Description: TODO
     * @Author: TomLiu
     * @Version: 1.0
     * @Date:  2022/6/21 18:40
     * @Parameters:
     * @Return
     */
    @Override
    public PageList<T> queryData(BaseQuery baseQuery) {
        List<T> rows = baseMapper.queryData(baseQuery);
        Integer total = baseMapper.queryCount(baseQuery);
        return new PageList<>(total, rows);
    }

    /*
     * @Title: batchDel
     * @Description: 批量删除
     * @Author: TomLiu
     * @Version: 1.0
     * @Date:  2022/6/25 11:16
     * @Parameters:
     * @Return
     */
    @Override
    @Transactional
    public void batchDel(Long[] ids) {
        baseMapper.batchDel(ids);
    }

    /*
     * @Title: update
     * @Description: TODO
     * @Author: TomLiu
     * @Version: 1.0
     * @Date:  2022/6/21 18:40
     * @Parameters:
     * @Return
     */
}
